package model;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JPanel;

public class Ball extends JPanel implements Common {

	private Point point;
	private int radius;
	private int dx;
	private int dy;

	public Ball(int x, int y, int radius) {

		this.radius = radius;
		this.point = new Point(x, y);
		this.dx = -1;
		this.dy = 0;
		this.zentralize();
	}

	private void zentralize() {
		this.point.setX(this.point.getX() - this.radius / 2);
		this.point.setY(this.point.getY() - this.radius / 2);
	}
	
	public void setBack(){
		this.point.setX(COMMON_SCREENWIDTH - this.radius / 2);
		this.point.setY(COMMON_SCREENHEIGHT- this.radius / 2);
	}
	

	@Override
	public int getX() {
		return this.point.getX();
	}

	@Override
	public int getY() {
		return this.point.getY();
	}

	public void act() {
		this.point.addX(dx);
		this.point.addY(dy);
	}

	public int getRadius() {
		return this.radius;
	}

	public void setRadius(int radius) {
		this.radius = radius;
	}

	public int getDx() {
		return dx;
	}

	public int getDy() {
		return dy;
	}

	public void setDx(int x) {
		this.dx = x;
	}

	public void setDy(int y) {
		this.dy = y;
	}
	
	public Point getMiddle() {
		return new Point(this.point.getX() + this.radius / 2, this.point.getY() + this.radius / 2);
	}

	@Override
	public void paint(Graphics g) {
		g.setColor(Color.WHITE);
		g.fillOval(this.point.getX(), this.point.getY(), this.radius,
				this.radius);
	}

	@Override
	public String toString() {
		String out = "";
		out += this.point;
		return out;
	}

}
